package com.example.casper.Experiment2024.java;

import static androidx.test.InstrumentationRegistry.getContext;
import static org.junit.Assert.*;

import android.net.Uri;

import com.example.casper.Experiment2024.R;
import com.example.casper.Experiment2024.items.Location;


import androidx.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import org.junit.After;
import org.junit.Before;



@RunWith(AndroidJUnit4.class)
public class LocationTest {
    private Location location;
    private Uri uri;
    @Before
    public void setUp() throws Exception {
        uri = Uri.parse("android.resource://" + getContext().getPackageName() + "/" + R.drawable.foot);
        location = new Location(uri, "广东省珠海市香洲区暨南大学", 22.255925, 113.541112, "Beautiful");
    }

    @After
    public void tearDown() throws Exception {
    }

    @Test
    public void getProvince() {
        assertEquals("广东省", location.getProvince());
    }

    @Test
    public void getPicPath() {
        assertEquals(uri, location.getPicPath());
    }

    @Test
    public void getLocationName() {
        assertEquals("广东省珠海市香洲区暨南大学", location.getLocationName());
    }

    @Test
    public void getLatitude() {
        assertEquals(22.255925, location.getLatitude(), 0.000001);
    }

    @Test
    public void getLongitude() {
        assertEquals(113.541112, location.getLongitude(), 0.000001);
    }

    @Test
    public void getFeeling() {
        assertEquals("Beautiful", location.getFeeling());
    }

    @Test
    public void setProvince() {
        location.setProvince("山西省");
        assertEquals("山西省", location.getProvince());
    }
    @Test
    public void setLocationName() {
        location.setLocationName("山西省临汾市尧都区鼓楼");
        assertEquals("山西省临汾市尧都区鼓楼", location.getLocationName());
    }

    @Test
    public void setLatitude() {
        location.setLatitude(23.123456);
        assertEquals(23.123456, location.getLatitude(), 0.000001);
    }

    @Test
    public void setLongitude() {
        location.setLongitude(114.123456);
        assertEquals(114.123456, location.getLongitude(), 0.000001);
    }

    @Test
    public void setFeeling() {
        location.setFeeling("Amazing");
        assertEquals("Amazing", location.getFeeling());
    }

    @Test
    public void testEquals() {
        uri = Uri.parse("android.resource://" + getContext().getPackageName() + "/" + R.drawable.foot);
        Location anotherLocation = new Location(uri, "广东省珠海市香洲区暨南大学", 22.255925, 113.541112, "Beautiful");
        assertTrue(location.equals(anotherLocation));
    }

    @Test
    public void testHashCode() {
        uri = Uri.parse("android.resource://" + getContext().getPackageName() + "/" + R.drawable.foot);
        Location anotherLocation = new Location(uri, "广东省珠海市香洲区暨南大学", 22.255925, 113.541112, "Beautiful");
        assertEquals(location.hashCode(), anotherLocation.hashCode());
    }

}